<?php
/**
 * Description of Buffer
 *
 * @author chedim
 */
class oCharBuffer extends oClass implements oInterfaceQueue
{
    protected $queue = array();

    public function  __construct(oString $source)
    {
        $enc = $source->encoding();
        for($i=0;$i<mb_strlen($source, $enc);$i++) {
            $this->push(new oChar($source($i, 1)));
        }
    }

    public function push($data)
    {
        if (!is_a($data, 'oChar')) {
            throw new eInvalidValue($data);
        }
        $this->queue[] = $data;
    }

    /**
     *
     * @return oChar
     */
    public function shift()
    {
        if (count($this->queue) == 0) {
                throw new eListEmpty();
        }
        return array_shift($this->queue);
    }

    public function is_empty()
    {
        return count($this->queue) == 0;
    }
}
?>
